package com.zoo.diannaopeijian.controller.component;

import com.zoo.diannaopeijian.controller.BaseController;
import com.zoo.diannaopeijian.domain.ComponentParameter;
import com.zoo.diannaopeijian.service.ComponentParameterService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 配件参数控制器
 */
@Controller
@RequestMapping("/componentParameter")
public class ComponentParameterController extends BaseController {
    @Resource
    private ComponentParameterService componentParameterService;

    @GetMapping("/")
    public ResponseEntity<List<ComponentParameter>> componentParameterGet(ComponentParameter componentParameter) {
        return ResponseEntity.ok(componentParameterService.getComponentParameter(componentParameter));
    }

    @PostMapping("/")
    public ResponseEntity<String> componentParameterPost(ComponentParameter componentParameter) {
        return ResponseEntity.ok(componentParameterService.addComponentParameter(componentParameter) ? success : fail);
    }

    @DeleteMapping("/{componentParameterId}")
    public ResponseEntity<String> componentParameterDelete(@PathVariable Integer componentParameterId) {
        return ResponseEntity.ok(componentParameterService.deleteComponentParameterById(componentParameterId) ? success : fail);
    }

    @PutMapping("/")
    public ResponseEntity<String> componentParameterPut(ComponentParameter componentParameter) {
        return ResponseEntity.ok(componentParameterService.updateComponentParameter(componentParameter) ? success : fail);
    }
}
